function Level(){
    var levelTFormat   = new TextFormat(font, timerSize, black);
    levelTFormat.align = TextFormatAlign.CENTER;
    
    Sprite.apply(this);
    this.pause = new Pause ();
    this.timer;
    this.timeLabel;
    this.bgColor = grey;
    this.render = render;
    
    
    this.bg = Game._game.bitmaps[Game.picturesPath+"levels/"+this.name+"/levelbg.jpg"];
    this.bg.x = 0;
    this.bg.y = 0;
    this.addChild(this.bg);
    function render(){
    }

    // Create Buttons
    this.skipButton = new Button("Preskočiť");
    this.skipButton.x = MainContainerWidth - this.skipButton.width - MARGIN;  
    this.skipButton.y = MainContainerHeight - this.skipButton.height - MARGIN;
    this.skipButton.addEventListener(MouseEvent.CLICK, clickSkip);
                
    this.pauseButton = new Button("Pozastaviť");
    this.pauseButton.x = MainContainerWidth - this.skipButton.width - this.pauseButton.width - 2*MARGIN;   
    this.pauseButton.y = MainContainerHeight - this.pauseButton.height - MARGIN;
    this.pauseButton.addEventListener(MouseEvent.CLICK, clickPause);
    
    this.backToMenu = new Button("Späť do menu");
    this.backToMenu.x = MARGIN;   
    this.backToMenu.y = MainContainerHeight - this.backToMenu.height - MARGIN;
    this.backToMenu.addEventListener(MouseEvent.CLICK, clickBack);
    
    this.restartButton = new Button("Reštartovať");
    this.restartButton.x = this.pauseButton.x - MARGIN - this.restartButton.width;   
    this.restartButton.y = MainContainerHeight - this.restartButton.height - MARGIN;
    this.restartButton.addEventListener(MouseEvent.CLICK, clickRestart);
                
    this.addChild(this.skipButton);
    this.addChild(this.pauseButton);
    this.addChild(this.backToMenu);            
    this.addChild(this.restartButton);
    // Create Timer
                
    this.timer = new Timer(100);            
    this.addChild(this.timer);
    
    // timeLabel
    this.updateTime = updateTime;
    this.getTimer = getTimer;
    this.timeLabel = new TextField();
    this.timeLabel.setTextFormat(levelTFormat);
    this.addChild (this.timeLabel);
    
    this.Run = levelRun;
    this.Start = LevelStart;
    
    this.updateTime();
    
    this.levelSolved = levelSolved;
    function levelSolved(){
        if (!Game._game.selectLevelMode)
            this.addChild (Game._game.menus["NextLevelMenu"]);
        else{
            this.addChild (Game._game.menus["SelectedLevelWin"]);
        }
    }
    
    function clickSkip(e) {
        //alert("Are you shure you want to skip?");
        e.target.parent.timer.TimerStop();
        Game._game.NextLevel();
    }
    function clickPause(e) {
        e.target.parent.pause.pausni (e);
    }

    function clickRestart(e) {
        e.target.parent.timer.TimerStop();
        Game._game.RestartLevel();
    }

    function clickBack(e) {
        e.target.parent.timer.TimerStop ();
        Game._game.LoadMainMenu();
        Game._game.LoadLevels();
        Game._game.score.restart();
        Game._game.selectLevelMode = false;
    }

    function updateTime(){
        var time = this.getTimer().getTime ();
        this.timeLabel.x = MARGIN;
        this.timeLabel.y = MARGIN;
        this.timeLabel.text = "time: " + Math.floor(time/10)+"."+(time%10);
        this.timeLabel.width = this.timeLabel.textWidth;
        this.timeLabel.height = this.timeLabel.textHeight;
    }

    function levelRun (){
        this.updateTime();
    }

    function getTimer (){
        return this.timer;
    }

    function LevelStart (){
        this.timer.TimerStart();
    }
}
Level.prototype = new Sprite();

// Game Manager  
  